﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace ConeDBServerNS
{
    [Serializable()]
    public class ConeEntity
    {
        [NonSerialized] public readonly ConeDatabase Database;
        public IDictionary<string, string> Tags;
        public Object Data;

        public ConeEntity()
        {
            Tags = new Dictionary<string, string>();
        }

        public byte[] GetBinary()
        {
            IFormatter formatter = new BinaryFormatter();
            Stream stream = new MemoryStream();
            byte[] entity = {};
            int streamlength = 0;
            
            formatter.Serialize(stream, this);
            streamlength = (int)stream.Length;
            entity = new byte[streamlength];
            stream.Read(entity, 0, streamlength);

            return entity;
        }
    }
}
